<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("comctrls.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class License_Renewal extends Page
{
       public $edDesc = null;
       public $hiddenEmp = null;
       public $JTSiteTheme1 = null;
       public $btnCancel = null;
       public $btnSubmit = null;
       public $memoComments = null;
       public $lblComments = null;
       public $lblDescription = null;
       public $dpDate = null;
       public $lblDate = null;
       public $Image3 = null;

       function btnCancelJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.close();
       <?php

       }

       function btnSubmitClick($sender, $params)
       {

       $query_license = "select * from emp_license_tbl where emp_id='".$this->hiddenEmp->getValue()."'";
       //die($query_rec_reminder);
       $result_licese = mysql_query($query_license)or die ("vehicle - ".mysql_error());
       $row_license = mysql_fetch_array($result_licese);


       $basis = $row_license['license_renew_date'];

       $date = date($basis);
       $date_computed = strtotime(date("Y-m-d", strtotime($date)) . "+3 year");
       $due_date = date("Y-m-d", $date_computed);


       mysql_query("UPDATE emp_license_tbl SET
       license_renew_date = '".$due_date."'
       WHERE emp_id = '".$this->hiddenEmp->getValue()."'")or die("UPDATE LICENSE".mysql_error());


       mysql_query("INSERT INTO emp_certification_tbl(company_id,
       emp_id,
       cert_date,
       description,
       comments,
       completed,
       completion_date)

       VALUES
       ('".$_SESSION['company_id']."',
       '".$this->hiddenEmp->getValue()."',
       '".$this->dpDate->Text."',
       '".$this->edDesc->Text."',
       '".$this->memoComments->Text."',
       '1',
       '".date('Y-m-d')."')") or die("INSERT LICENSE - ".mysql_error());


       echo '<script language=javascript>
       alert("Reminder completed!");
       //window.opener.location.reload();
       //window.top.location.reload();
       window.close()
       window.top.opener.top.location.reload();
       </script>';


       }

       function License_RenewalCreate($sender, $params)
       {
       $emp = $_GET['emp'];
       $this->hiddenEmp->setValue($emp);

       $this->dpDate->Text = date('Y-m-d');
       $this->edDesc->Text = 'License Renewal';
       $this->memoComments->Text = 'Reminder Completed on:'.''.date('Y-m-d');
       }


}

global $application;

global $License_Renewal;

//Creates the form
$License_Renewal=new License_Renewal($application);

//Read from resource file
$License_Renewal->loadResource(__FILE__);

//Shows the form
$License_Renewal->show();

?>